home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 August / CHIP_CD_2004-08.iso / software / amc / amc_install.exe / {app} / Scripts / IMDB (large pic).ifs < prev    next >
Encoding:
Text File  |  2004-03-20  |  23.2 KB  |  792 lines

  1. // GETINFO SCRIPTING
  2. // IMDB (US) import with large picture (usually from Amazon.com)
  3.  
  4. (***************************************************
  5.  *  Movie importation script for:                  *
  6.  *      IMDB (US), http://us.imdb.com              *
  7.  *                                                 *
  8.  *  (c) 2002-2004 Antoine Potten                   *
  9.  *                          software@antp.be       *
  10.  *  Contributors :                                 *
  11.  *    Danny Falkov                                 *
  12.  *    Kai Blankenhorn                              *
  13.  *    lboregard                                    *
  14.  *    Ork <ork@everydayangels.net>                 *
  15.  *    Trekkie <Asimov@hotmail.com>                 *
  16.  *                                                 *
  17.  *  For use with Ant Movie Catalog 3.4.0           *
  18.  *  www.antp.be/software/moviecatalog              *
  19.  *                                                 *
  20.  *  This program is free software; you can         *
  21.  *  redistribute it and/or modify it under the     *
  22.  *  terms of the GNU General Public License as     *
  23.  *  published by the Free Software Foundation;     *
  24.  *  either version 2 of the License, or (at your   *
  25.  *  option) any later version.                     *
  26.  ***************************************************)
  27.  
  28.  
  29. program IMDb;
  30.  
  31. const
  32.   ExternalPictures = False;
  33.     { True: Pictures will be stored as external files in the folder of the
  34.             catalog
  35.       False: Pictures will be stored inside the catalog (only for .amc files) }
  36.   ManualPictureSelect = True;
  37.     { True: If no Title Match found a picture selection window appears
  38.       False: Revert to IMDB picture }
  39.   ImportLanguage = False,
  40.     { True: Import value of Language field }
  41.   DescriptionToImport = 2;
  42.    {
  43.       2 = import longest
  44.       1 = import short (from main page, faster)
  45.       0 = display list to select a description
  46.    }
  47.  
  48. var
  49.   MovieName: string;
  50.   MovieURL: string;
  51.  
  52. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  53. var
  54.   i: Integer;
  55. begin
  56.   Result := -1;
  57.   if StartAt < 0 then
  58.     StartAt := 0;
  59.   for i := StartAt to List.Count-1 do
  60.     if Pos(Pattern, List.GetString(i)) <> 0 then
  61.     begin
  62.       Result := i;
  63.       Break;
  64.     end;
  65. end;
  66.  
  67. procedure AnalyzePage(Address: string);
  68. var
  69.   Page: TStringList;
  70. begin
  71.   Page := TStringList.Create;
  72.   Page.Text := GetPage(Address);
  73.   if pos('<title>IMDb', Page.Text) = 0 then
  74.   begin
  75.     AnalyzeMoviePage(Page)
  76.   end else
  77.   begin
  78.     PickTreeClear;
  79.     AddMoviesTitles(Page, '<b>Exact Matches</b>');
  80.     AddMoviesTitles(Page, '<b>Partial Matches</b>');
  81.     AddMoviesTitles(Page, '<b>Approximate Matches</b>');
  82.     if PickTreeExec(Address) then
  83.       AnalyzePage(Address);
  84.   end;
  85.   Page.Free;
  86. end;
  87.  
  88. function FindValue(BeginTag, EndTag: string; Page: TStringList; var LineNr: Integer; var Line: string): string;
  89. var
  90.   BeginPos, EndPos: Integer;
  91.   Value: string;
  92. begin
  93.   Result := '';
  94.   Value := '';
  95.   BeginPos := Pos(BeginTag, Line);
  96.   if BeginPos > 0 then
  97.   begin
  98.     BeginPos := BeginPos + Length(BeginTag);
  99.     if BeginTag = EndTag then
  100.     begin
  101.       Delete(Line,1,BeginPos-1);
  102.       BeginPos := 1;
  103.     end;
  104.     EndPos := pos(EndTag, Line);
  105.     while ((EndPos = 0) and (LineNr < Page.Count-1 )) do
  106.     begin
  107.       Value := Value + copy(Line, BeginPos, Length(Line) - BeginPos);
  108.       // Next Line
  109.       BeginPos := 1;
  110.       LineNr := LineNr + 1;
  111.       Line := Page.GetString(LineNr);
  112.       if Value = '' then
  113.         Exit;
  114.       EndPos := Pos(EndTag, Line);
  115.     end;
  116.     Value := Value + copy(Line, BeginPos, EndPos - BeginPos);
  117.    end;
  118.   Result := Value;
  119. end;
  120.  
  121. procedure AnalyzeMoviePage(Page: TStringList);
  122. var
  123.   Line, Value, Value2, FullValue: string;
  124.   LineNr, BeginPos, EndPos, DescrImport: Integer;
  125.   AllTitles: TStringList;
  126. begin
  127.   DescrImport := DescriptionToImport;
  128.   if (DescrImport <> 1) and (Pos('<a href="plotsummary">', Page.Text) = 0) then
  129.     DescrImport := 1;
  130.  
  131.   MovieURL := 'http://imdb.com/title/tt' + copy(Page.Text, pos('<a href="/title/tt',Page.Text)+19, 7);
  132.  
  133.   // URL
  134.   SetField(fieldURL, MovieURL);
  135.  
  136.   AllTitles := TStringList.Create;
  137.  
  138.   // Original Title & Year
  139.   LineNr := FindLine('<title>', Page, 0);
  140.   Line := Page.GetString(LineNr);
  141.   if LineNr > -1 then
  142.   begin
  143.     BeginPos := pos('<title>', Line);
  144.     if BeginPos > 0 then
  145.       BeginPos := BeginPos + 7;
  146.     EndPos := pos('(', Line);
  147.     if EndPos = 0 then
  148.       EndPos := Length(Line);
  149.     Value := copy(Line, BeginPos, EndPos - BeginPos - 1);
  150.     HTMLDecode(Value);
  151.     SetField(fieldOriginalTitle, Value);
  152.     // IMDB original Title
  153.     AllTitles.Add(Value);
  154.     // IMDB Corrected Title
  155.     Value:=TransformIMDBTitle(Value);
  156.     AllTitles.Add(Value);
  157.     BeginPos := pos('(', Line) + 1;
  158.     if BeginPos > 0 then
  159.     begin
  160.       EndPos := Pos('/I', Line);
  161.       if EndPos < BeginPos then
  162.         EndPos := pos(')', Line);
  163.       Value := copy(Line, BeginPos, EndPos - BeginPos);
  164.       SetField(fieldYear, Value);
  165.     end;
  166.   end;
  167.  
  168.   // Rating
  169.   LineNr := FindLine('User Rating:', Page, 0);
  170.   if LineNr > -1 then
  171.   begin
  172.     Line := Page.GetString(LineNr + 4);
  173.     if Pos('/10', Line) > 0 then
  174.     begin
  175.       BeginPos := pos('<b>', Line) + 3;
  176.       Value := IntToStr(Round(StrToInt(StrGet(Line, BeginPos), 0) + (StrToInt(StrGet(Line, BeginPos + 2), 0) / 10)));
  177.       SetField(fieldRating, Value);
  178.     end;
  179.   end;
  180.  
  181.   // Language
  182.   LineNr := FindLine('Language:', Page, 0);
  183.   if LineNr > -1 then
  184.   begin
  185.     Line := Page.GetString(LineNr + 1);
  186.     BeginPos := pos('/">', Line) + 3;
  187.     EndPos := pos('</a>', Line);
  188.     if EndPos = 0 then
  189.       EndPos := Length(Line);
  190.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  191.     if ImportLanguage then
  192.       SetField(fieldLanguages, Value);
  193.   end;
  194.  
  195.   GetMoviePicture(Value, Page, AllTitles);
  196.   AllTitles.Free;
  197.  
  198.   // Director
  199.   LineNr := FindLine('Directed by', Page, 0);
  200.   if LineNr > -1 then
  201.   begin
  202.     FullValue := '';
  203.     Line := Page.GetString(LineNr + 1);
  204.     repeat
  205.       BeginPos := pos('">', Line) + 2;
  206.       EndPos := pos('</a>', Line);
  207.       Value := copy(Line, BeginPos, EndPos - BeginPos);
  208.       if (Value <> '(more)') and (Value <> '') then
  209.       begin
  210.         if FullValue <> '' then
  211.           FullValue := FullValue + ', ';
  212.         FullValue := FullValue + Value;
  213.       end;
  214.       Delete(Line, 1, EndPos);
  215.     until Pos('</a>', Line) = 0;
  216.     HTMLDecode(FullValue);
  217.     SetField(fieldDirector, FullValue);
  218.   end;
  219.  
  220.   // Actors
  221.   LineNr := FindLine('ast overview', Page, 0);
  222.   if LineNr = -1 then
  223.     LineNr := FindLine('redited cast', Page, 0);
  224.   if LineNr > -1 then
  225.   begin
  226.     FullValue := '';
  227.     Line := Page.GetString(LineNr);
  228.     repeat
  229.       BeginPos := Pos('<td valign="top">', Line);
  230.       if BeginPos > 0 then
  231.       begin
  232.         Delete(Line, 1, BeginPos);
  233.         Line := copy(Line, 25, Length(Line));
  234.         BeginPos := pos('">', Line) + 2;
  235.         EndPos := pos('</a>', Line);
  236.         if EndPos = 0 then
  237.           EndPos := Pos('</td>', Line);
  238.         Value := copy(Line, BeginPos, EndPos - BeginPos);
  239.         if (Value <> '(more)') and (Value <> '') then
  240.         begin
  241.           BeginPos := pos('.... </td><td valign="top">', Line);
  242.           if BeginPos > 0 then
  243.           begin
  244.             EndPos := pos('</td></tr>', Line);
  245.             BeginPos := BeginPos + 27;
  246.             Value2 := copy(Line, BeginPos, EndPos - BeginPos);
  247.             if Value2 <> '' then
  248.             begin
  249.               Value := Value + ' (as ' + Value2 + ')';
  250.             end;
  251.           end;
  252.           if FullValue <> '' then
  253.             FullValue := FullValue + ', ';
  254.           FullValue := FullValue + Value;
  255.         end;
  256.         EndPos := Pos('</td></tr>', Line);
  257.         Delete(Line, 1, EndPos);
  258.       end else
  259.       begin
  260.         Line := '';
  261.       end;
  262.     until Line = '';
  263.     HTMLDecode(FullValue);
  264.     SetField(fieldActors, FullValue);
  265.   end;
  266.  
  267.   //Country
  268.   LineNr := FindLine('Country:', Page, 0);
  269.   if LineNr > -1 then
  270.   begin
  271.     Line := Page.GetString(LineNr + 1);
  272.     BeginPos := pos('/">', Line) + 3;
  273.     EndPos := pos('</a>', Line);
  274.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  275.     HTMLDecode(Value);
  276.     SetField(fieldCountry, Value);
  277.   end;
  278.  
  279.   //Category
  280.   LineNr := FindLine('Genre:', Page, 0);
  281.   if LineNr > -1 then
  282.   begin
  283.     Line := Page.GetString(LineNr + 1);
  284.     BeginPos := pos('/">', Line) + 3;
  285.     EndPos := pos('</a>', Line);
  286.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  287.     HTMLDecode(Value);
  288.     SetField(fieldCategory, Value);
  289.   end;
  290.  
  291.   //Description
  292.   LineNr := FindLine('Plot Summary:', Page, 0);
  293.   if LineNr < 1 then
  294.     LineNr := FindLine('Plot Outline:', Page, 0);
  295.   if LineNr > -1 then
  296.   begin
  297.     Line := Page.GetString(LineNr);
  298.     BeginPos := pos('</b>', Line) + 5;
  299.     EndPos := pos('<a href', Line);
  300.     if EndPos < 1 then
  301.     begin
  302.       Line := Line + Page.GetString(LineNr+1);
  303.       EndPos := pos('<br><br>', Line);
  304.       if EndPos < 1 then
  305.         EndPos := Length(Line);
  306.     end;
  307.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  308.     HTMLDecode(Value);
  309.     case DescrImport of
  310.       0:
  311.         begin
  312.           PickListClear;
  313.           PickListAdd(Value);
  314.           GetDescriptions(GetField(fieldURL) + 'plotsummary');
  315.           if PickListExec('Select a description for "' + MovieName + '"', Value) then
  316.             SetField(fieldDescription, Value);
  317.         end;
  318.       1:
  319.         SetField(fieldDescription, Value);
  320.       2:
  321.         SetField(fieldDescription, GetDescriptions(MovieURL + 'plotsummary'));
  322.     end;
  323.   end;
  324.  
  325.   // Comments
  326.   LineNr := FindLine('<b>Summary:</b>', Page, 0);
  327.   if LineNr > -1 then
  328.   begin
  329.     Value := '';
  330.     repeat
  331.       LineNr := LineNr + 1;
  332.       Line := Page.GetString(LineNr);
  333.       EndPos := Pos('</blockquote>', Line);
  334.       if EndPos = 0 then
  335.         EndPos := Length(Line)
  336.       else
  337.         EndPos := EndPos - 1;
  338.       Value := Value + Copy(Line, 1, EndPos) + ' ';
  339.     until Pos('</blockquote>', Line) > 0;
  340.     HTMLDecode(Value);
  341.     Value := StringReplace(Value, '<br>', #13#10);
  342.     Value := StringReplace(Value, #13#10+' ', #13#10);
  343.     SetField(fieldComments, Value);
  344.   end;
  345.  
  346.   // Length
  347.   LineNr := FindLine('Runtime:', Page, 0);
  348.   if LineNr > -1 then
  349.   begin
  350.     Line := Page.GetString(LineNr + 1);
  351.     EndPos := pos(' min', Line);
  352.     if EndPos = 0 then
  353.       EndPos := pos('  /', Line);
  354.     if EndPos = 0 then
  355.       EndPos := Length(Line);
  356.     if Pos(':', Line) < EndPos then
  357.       BeginPos := Pos(':', Line) + 1
  358.     else
  359.       BeginPos := 1;
  360.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  361.     SetField(fieldLength, Value);
  362.   end;
  363.  
  364.   DisplayResults;
  365. end;
  366.  
  367. procedure GetMoviePicture(Language: string; Page, AllTitles: TStringList);
  368. var
  369.   Line, Value, Value2, Aka, PictureAddress: string;
  370.   AmazonPage: TStringList;
  371.   FoundOnAmazon, PickTreeSelected, PictureAvailable: Boolean;
  372.   TitleRef, ImgRef, NoImage: string;
  373.   LineNr, BeginPos, EndPos, PickTreeCount, ParagraphIndex, Index, TitleLine, LastMatch: Integer;
  374. begin
  375.   FoundOnAmazon := False;
  376.  
  377.   // Find Alternate Titles for Movies which are not in English
  378.   Aka := '';
  379.   if Language <> 'English' Then
  380.   begin
  381.     LineNr:= FindLine('Also Known As',Page,0);
  382.     EndPos:=0;
  383.     if LineNr > -1 then
  384.     begin
  385.       Line := Page.GetString(LineNr);
  386.       repeat
  387.         Aka:=FindValue('<br>','<br>',Page,LineNr,Line);
  388.         if Aka <> '' then
  389.         begin
  390.           BeginPos:=1;
  391.           EndPos:=Pos('(',Line);
  392.           if EndPos = 0 then
  393.             EndPos := Length(Aka);
  394.           Value := copy(Aka, BeginPos, EndPos - BeginPos - 1);
  395.           Value:=TransFormIMDBTitle(Value);
  396.           AllTitles.Add(Value);
  397.         end;
  398.       until (Pos('Runtime',Line) > 0) or (Pos('MPAA',Line) > 0 ) or (Pos('Country', Line) > 0) or (Pos('Certification', Line) > 0);
  399.     end;
  400.   end;
  401.  
  402.   TitleRef:='dvd>';
  403.   ImgRef:='dvd><img';
  404.   NoImage:='/icons/dvd-no-image.gif';
  405.   LineNr := FindLine('title="DVD available at Amazon.com"', Page, 0);
  406.   if LineNr = -1 then
  407.   begin
  408.     LineNr := FindLine('title="VHS available at Amazon.com"', Page, 0);
  409.     if LineNr > -1 then
  410.     begin
  411.       TitleRef:='video>';
  412.       ImgRef:='video><img';
  413.       NoImage:='/icons/video-no-image.gif';
  414.     end;
  415.   end;
  416.  
  417.   if LineNr > -1 then
  418.   begin
  419.     Line := Page.GetString(LineNr);
  420.     if(TitleRef='dvd>') then
  421.     begin
  422.       EndPos := pos('title="DVD', Line);
  423.       BeginPos := pos('title="VHS', Line);
  424.       while (BeginPos > 0) and (BeginPos<EndPos) do
  425.       begin
  426.         Delete(Line, 1, BeginPos+1);
  427.         BeginPos := pos('title="VHS', Line);
  428.       end;
  429.     end;
  430.     BeginPos := Pos('href="', Line) + 5;
  431.     Delete(Line, 1, BeginPos);
  432.     EndPos := Pos('"', Line);
  433.     Value := Copy(Line, 1, EndPos - 1);
  434.     AmazonPage := TStringList.Create;
  435.     AmazonPage.Text := GetPage('http://us.imdb.com' + Value);
  436.  
  437.     // Original Title
  438.     Value2 := AllTitles.GetString(0);
  439.     Value2 := TransFormIMDBTitle(Value2);
  440.  
  441.     PickTreeClear;
  442.     PickTreeCount := 0;
  443.     PickTreeAdd('Available Titles for matching a picture to: ' + Value2, '');
  444.  
  445.     ParagraphIndex := 1;
  446.     LineNr := 0;
  447.     LastMatch := -1;
  448.     TitleLine := -1;
  449.     repeat
  450.       LineNr := FindLine('<b>'+IntToStr(ParagraphIndex)+'.', AmazonPage, LineNr);
  451.  
  452.       if LineNr > -1 then
  453.       begin
  454.         TitleLine:=LineNr;
  455.         Value:='';
  456.         PictureAvailable:=False;
  457.         repeat
  458.           TitleLine:=TitleLine +1;
  459.           Line:= AmazonPage.GetString(TitleLine);
  460.           BeginPos:=0;
  461.           if Pos(TitleRef,Line) > 0 then
  462.           begin
  463.             if Pos(ImgRef,Line) = 0 then
  464.             begin
  465.               for Index:=0 to AllTitles.Count -1 do
  466.               begin
  467.                 Value2:=AllTitles.GetString(Index);
  468.                 BeginPos:=Pos(Value2,Line);
  469.                 if BeginPos > 0 then
  470.                   Break;
  471.               end;
  472.               // Match not found
  473.               if BeginPos = 0 then
  474.               begin
  475.                 BeginPos:=Pos(TitleRef,Line)+Length(TitleRef);
  476.                 EndPos:=Pos('</a>',Line);
  477.                 Value:=Copy(Line,BeginPos,EndPos-BeginPos);
  478.               end;
  479.             end
  480.             else
  481.             begin
  482.               PictureAvailable:=(Pos(NoImage,Line) = 0);
  483.               PictureAddress:=IntToStr(TitleLine);
  484.             end;
  485.           end;
  486.           if BeginPos > 0 then
  487.             Break;
  488.         until (Pos('</table>',Line ) > 0);
  489.  
  490.         // Try to Find a Title Match
  491.         if Pos(Value2,Line) > 0 then
  492.         begin
  493.           // Compare Current Title to Original
  494.           BeginPos := Pos(TitleRef, Line) + Length(TitleRef) -1;
  495.           Delete(Line, 1, BeginPos);
  496.           EndPos:= Pos('(',Line);
  497.           if EndPos = 0 Then
  498.             EndPos := Pos('</a>', Line);
  499.           Value := Copy(Line, 1, EndPos - 1);
  500.           Value:= Trim(Value);
  501.           if Value = Value2 then
  502.           begin
  503.             if PictureAvailable then
  504.               LastMatch:=LineNr;
  505.               //Break
  506.           end;
  507.         end;
  508.         if PictureAvailable then
  509.         begin
  510.           PickTreeAdd(Value,PictureAddress);
  511.           PickTreeCount:=PickTreeCount+1;
  512.         end;
  513.       end;
  514.       ParagraphIndex:=ParagraphIndex+1;
  515.     until (LineNr = -1);
  516.     LineNr:=LastMatch;
  517.     if (LineNr = -1) then
  518.     begin
  519.       // Handle Amazon Page Redirection(s)
  520.       LineNr:= FindLine('You clicked on this item',AmazonPage,0);
  521.       if (LineNr = -1) then
  522.         LineNr:=FindLine('Customers who bought',AmazonPage,0);
  523.       // Display the Picture Selection Window
  524.       if (LineNr = -1) and ManualPictureSelect and (PickTreeCount > 0) then
  525.       begin
  526.         PickTreeSelected:=PickTreeExec(PictureAddress);
  527.         if PickTreeSelected then
  528.           LineNr:=StrToInt(PictureAddress,0);
  529.       end;
  530.       if (LineNr > -1 ) then
  531.       begin
  532.         LineNr := FindLine('src="http://images.amazon.com/images/P/',AmazonPage, LineNr);
  533.         if not PickTreeSelected then
  534.           TitleLine:= FindLine('/exec/obidos/ASIN/',AmazonPage, 0);
  535.         if (LineNr > TitleLine) then
  536.           LineNr:=-1;
  537.         if LineNr > -1 then
  538.         begin
  539.           Line := AmazonPage.GetString(LineNr);
  540.           BeginPos := Pos('src="http://images.amazon.com/images/P/', Line) + 4;
  541.           Delete(Line, 1, BeginPos);
  542.           EndPos := Pos('"', Line);
  543.           Value := Copy(Line, 1, EndPos - 1);
  544.           Value := StringReplace(Value, 'TZZZZZZZ', 'LZZZZZZZ');
  545.           Value := StringReplace(Value, 'THUMBZZZ', 'LZZZZZZZ');
  546.           GetPicture(Value, ExternalPictures);
  547.           FoundOnAmazon := True;
  548.         end;
  549.       end;
  550.     end
  551.     else
  552.     begin
  553.       LineNr := FindLine('http://images.amazon.com/images/P/', AmazonPage, LineNr);
  554.       if LineNr < TitleLine then
  555.       begin
  556.         Line := AmazonPage.GetString(LineNr);
  557.         BeginPos := Pos('src="', Line) + 4;
  558.         Delete(Line, 1, BeginPos);
  559.         EndPos := Pos('"', Line);
  560.         Value := Copy(Line, 1, EndPos - 1);
  561.         Value := StringReplace(Value, 'THUMBZZZ', 'LZZZZZZZ');
  562.         GetPicture(Value, ExternalPictures);
  563.         FoundOnAmazon := True;
  564.       end;
  565.     end;
  566.     AmazonPage.Free;
  567.   end;
  568.  
  569.   if not FoundOnAmazon then
  570.   begin
  571.     {  not found on Amazon, so taking what's available directly on IMDB.
  572.        if we are lucky, a picture from amazon but directly linked in the page  }
  573.     LineNr := FindLine('<img alt="cover" align="left" src="http://ia.imdb.com/media/imdb/', Page, 0);
  574.     if LineNr < 0 then
  575.       LineNr := FindLine('<img alt="cover" align="left" src="http://posters.imdb.com/', Page, 0);
  576.     if LineNr < 0 then
  577.       LineNr := FindLine('<img alt="cover" align="left" src="http://images.amazon.com/', Page, 0);
  578.     if LineNr > -1 then
  579.     begin
  580.       Line := Page.GetString(LineNr);
  581.       BeginPos := pos('src="', Line) + 4;
  582.       Delete(Line, 1, BeginPos);
  583.       EndPos := pos('"', Line);
  584.       Value := copy(Line, 1, EndPos - 1);
  585.       Value := StringReplace(Value, 'MZZZZZZZ', 'LZZZZZZZ'); // change URL to get the Large instead of Small image
  586.       GetPicture(Value, ExternalPictures);
  587.     end;
  588.   end;
  589. end;
  590.  
  591. function TransformIMDBTitle(Title: string): string;
  592. var
  593.   BeginPos, EndPos: Integer;
  594.   Value: string;
  595.   Words: array of string;
  596.   Articles: array of string;
  597.   Replace,Original: string;
  598.   Index, CommaCount: Integer;
  599. Begin
  600.   // Original Title
  601.   Result:=Title;
  602.  
  603.   Setarraylength(Words,11);
  604.   Words[0]:=' In ';
  605.   Words[1]:=' On ';
  606.   Words[2]:=' Of ';
  607.   Words[3]:=' As ';
  608.   Words[4]:=' The ';
  609.   Words[5]:=' At ';
  610.   Words[6]:=' And A ';
  611.   Words[7]:=' And ';
  612.   Words[8]:=' An ';
  613.   Words[9]:=' To ';
  614.   Words[10]:=' For ';
  615.  
  616.   SetArrayLength(Articles,35);
  617.   Articles[0]:=' The';
  618.   Articles[1]:=' a';
  619.   Articles[2]:=' An';
  620.   Articles[3]:=' Le';
  621.   Articles[4]:=' L''';
  622.   Articles[5]:=' Les';
  623.   Articles[6]:=' Der';
  624.   Articles[7]:=' Das';
  625.   Articles[8]:=' Die';
  626.   Articles[9]:=' Des';
  627.   Articles[10]:=' Dem';
  628.   Articles[11]:=' Den';
  629.   Articles[12]:=' Ein';
  630.   Articles[13]:=' Eine';
  631.   Articles[14]:=' Einen';
  632.   Articles[15]:=' Einer';
  633.   Articles[16]:=' Eines';
  634.   Articles[17]:=' Einem';
  635.   Articles[18]:=' Il';
  636.   Articles[19]:=' Lo';
  637.   Articles[20]:=' La';
  638.   Articles[21]:=' I';
  639.   Articles[22]:=' Gli';
  640.   Articles[23]:=' Le';
  641.   Articles[24]:=' Uno';
  642.   Articles[25]:=' Una';
  643.   Articles[26]:=' Un''';
  644.   Articles[27]:=' O';
  645.   Articles[28]:=' Os';
  646.   Articles[29]:=' As';
  647.   Articles[30]:=' El';
  648.   Articles[31]:=' Los';
  649.   Articles[32]:=' Las';
  650.   Articles[33]:=' Unos';
  651.   Articles[34]:=' Unas';
  652.  
  653.   // Count the Comma in The Title
  654.   CommaCount := 0;
  655.   EndPos := 0;
  656.   Value := Title;
  657.   repeat
  658.      BeginPos := Pos(',', Value);
  659.      if BeginPos > 0 then
  660.      begin
  661.        Delete(Value, 1, BeginPos);
  662.        CommaCount := CommaCount + 1;
  663.        EndPos := EndPos + BeginPos;
  664.      end;
  665.   until( Pos(',',Value) = 0);
  666.  
  667.   // Compare the Article to a list of known ones
  668.   for Index := 0 to 34 do
  669.   begin
  670.     if Pos(Articles[Index], Value) <> 0 then
  671.     begin
  672.        CommaCount := 1;
  673.        BeginPos := EndPos;
  674.        Break;
  675.     end;
  676.   end;
  677.  
  678.   if (BeginPos > 0) and (CommaCount = 1) then
  679.   begin
  680.     Value := Copy(Title, BeginPos + 1, Length(Title));
  681.     Value := Trim(Value);
  682.     Result := Value + ' ' + Copy(Title, 1, BeginPos - 1);
  683.   end;
  684.  
  685.   BeginPos := Pos(': ', Result);
  686.   if BeginPos > 0 then
  687.     Result := StringReplace(Result, ': ', ' - ');
  688.  
  689.   Result := AnsiMixedCase(Result, ' ');
  690.  
  691.   for Index := 0 to 10 do
  692.   begin
  693.     if Pos(Words[Index],Result) <> 0 then
  694.     begin
  695.       Original := Words[Index];
  696.       Replace := AnsiLowerCase(Original);
  697.       Result := StringReplace(Result, Original, Replace);
  698.     end;
  699.   end;
  700.  
  701.   Result := StringReplace(Result, ' - the ', ' - The ');
  702.   Result := Trim(Result);
  703. end;
  704.  
  705. function GetDescriptions(Address: string): string;
  706. var
  707.   Line, Value: string;
  708.   LineNr: Integer;
  709.   BeginPos, EndPos,Longest: Integer;
  710.   Page: TStringList;
  711. begin
  712.   Result := '';
  713.   Longest := 0;
  714.   Page := TStringList.Create;
  715.   Page.Text := GetPage(Address);
  716.   LineNr := FindLine('<p class="plotpar">', Page, 0);
  717.   while LineNr > -1 do
  718.   begin
  719.     Value := '';
  720.     repeat
  721.       Line := Page.GetString(LineNr);
  722.       BeginPos := pos('"plotpar">', Line);
  723.       if BeginPos > 0 then
  724.         BeginPos := BeginPos + 10
  725.       else
  726.         BeginPos := 1;
  727.       EndPos := pos('</p>', Line);
  728.       if EndPos < 1 then
  729.         EndPos := Length(Line) + 1;
  730.       if Value <> '' then
  731.         Value := Value + ' ';
  732.       Value := Value + copy(Line, BeginPos, EndPos - BeginPos);
  733.       LineNr := LineNr + 1;
  734.     until (pos('</p>', Line) > 0) or (LineNr = Page.Count);
  735.     HTMLDecode(Value);
  736.     PickListAdd(Value);
  737.  
  738.     if Length(Value) > Longest then
  739.     begin
  740.       Result := Value;
  741.       Longest := Length(Value);
  742.     end;
  743.  
  744.     LineNr := FindLine('<p class="plotpar">', Page, LineNr);
  745.   end;
  746.   Page.Free;
  747. end;
  748.  
  749. procedure AddMoviesTitles(Page: TStringList; Tag: string);
  750. var
  751.   Line: string;
  752.   LineNr: Integer;
  753.   MovieTitle, MovieAddress: string;
  754.   StartPos: Integer;
  755. begin
  756.   LineNr := FindLine(tag, Page, 0);
  757.   if LineNr > -1 then
  758.   begin
  759.     Line := Page.GetString(LineNr);
  760.     HTMLRemoveTags(Line);
  761.     PickTreeAdd(Trim(Line), '');
  762.     LineNr := LineNr + 5;
  763.     Line := Page.GetString(LineNr);
  764.     repeat
  765.       StartPos := pos('href="', Line) + 5;
  766.       Delete(Line, 1, StartPos);
  767.       MovieAddress := Copy(Line, 1, pos('">', Line) - 1);
  768.       StartPos := Pos('">', Line) + 2;
  769.       MovieTitle := Copy(Line, StartPos, Pos('</a>', Line) - StartPos);
  770.       HTMLDecode(Movietitle);
  771.       PickTreeAdd(MovieTitle, 'http://us.imdb.com' + MovieAddress);
  772.       LineNr := LineNr + 2;
  773.       Line := Page.GetString(LineNr);
  774.     until Pos('</table>', Line) > 0;
  775.   end;
  776. end;
  777.  
  778. begin
  779.   if CheckVersion(3,4,0) then
  780.   begin
  781.     MovieName := GetField(fieldOriginalTitle);
  782.     if MovieName = '' then
  783.       MovieName := GetField(fieldTranslatedTitle);
  784.     if Input('IMDb Import', 'Enter the title of the movie:', MovieName) then
  785.     begin
  786.       AnalyzePage('http://us.imdb.com/Tsearch?title='+UrlEncode(MovieName));
  787.     end;
  788.   end
  789.   else
  790.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
  791. end.
  792.